<?php

namespace App\Models\ModelManage;

use Eloquent as Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * Class TableRelation
 * @package App\Models\ModelManage
 * @version August 7, 2018, 5:45 pm CST
 *
 * @property \App\Models\ModelManage\Table table
 * @property \App\Models\ModelManage\TableField tableField
 * @property \App\Models\ModelManage\Table table
 * @property \App\Models\ModelManage\TableField tableField
 * @property integer master
 * @property integer mkey
 * @property integer relations
 * @property integer slave
 * @property integer skey
 */
class TableRelation extends Model
{
    use SoftDeletes;


    public $table = 'table_relations';
    

    protected $dates = ['deleted_at'];


    public $fillable = [
        'master',
        'mkey',
        'relations',
        'slave',
        'skey'
    ];

    /**
     * The attributes that should be casted to native types.
     *
     * @var array
     */
    protected $casts = [
        'master' => 'integer',
        'mkey' => 'integer',
        'relations' => 'integer',
        'slave' => 'integer',
        'skey' => 'integer'
    ];

    /**
     * Validation rules
     *
     * @var array
     */
    public static $rules = [
        
    ];

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function masterTable()
    {
        return $this->hasOne(\App\Models\ModelManage\Table::class, 'id', 'master');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function masterTableField()
    {
        return $this->hasOne(\App\Models\ModelManage\TableField::class, 'id', 'mkey');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function slaveTable()
    {
        return $this->hasOne(\App\Models\ModelManage\Table::class, 'id', 'slave');
    }

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     **/
    public function slaveTableField()
    {
        return $this->hasOne(\App\Models\ModelManage\TableField::class, 'id', 'skey');
    }
}
